/**
 * 
 */
package com.feib.stms.action;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontBind;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.DateTypeConverter;
import net.sourceforge.stripes.validation.Validate;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.support.ResourceBundleMessageSource;

import com.feib.stms.model.ActionLog;
import com.feib.stms.model.Group;
import com.feib.stms.model.LabelValue;
import com.feib.stms.model.MenuItem;
import com.feib.stms.model.Securities;
import com.feib.stms.model.User;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.ActionLogService;
import com.feib.stms.service.GroupService;
import com.feib.stms.service.SecuritiesService;
import com.feib.stms.util.MenuLoader;
import com.feib.stms.util.UserUtil;

/**
 * @title (#)Soez9012ActionBean.java<br>
 * @description 操作記錄查詢 <br>
 * @author Karl Chen<br>
 * @version 1.0.0 2012/05/16
 * @2012/05/16 create by Karl Chen<br>
 *
 */
public class Stms9012ActionBean extends BaseActionBean 
{
	private static final long serialVersionUID = 8222509856160478869L;

	private static final String DEFAULT_JSP = "/WEB-INF/views/stms9012/stms9012.jsp";

	/* 畫面sortHeader傳回來的值 */
	private static List<String> SORT_KEYS = new ArrayList<String>();
	static{
		SORT_KEYS.add("inDateTime".toLowerCase());
		SORT_KEYS.add("parentActionName".toLowerCase());
		SORT_KEYS.add("actionName".toLowerCase());
		SORT_KEYS.add("eventName".toLowerCase());
		SORT_KEYS.add("remoteAddr".toLowerCase());
		SORT_KEYS.add("userId".toLowerCase());
		SORT_KEYS.add("securities".toLowerCase());    	
	}

	/* 使用SORT_KEYS作key值取得對應的資料庫欄位名稱 */
	private static Map<String,String> SORT_FIELD = new HashMap<String,String>();
	static{  
		SORT_FIELD.put("inDateTime".toLowerCase(), "act.in_date_time");
		SORT_FIELD.put("parentActionName".toLowerCase(), "act.parent_action_name");
		SORT_FIELD.put("actionName".toLowerCase(), "act.action_name");
		SORT_FIELD.put("eventName".toLowerCase(), "act.event_name");
		SORT_FIELD.put("remoteAddr".toLowerCase(), "act.remote_addr");
		SORT_FIELD.put("userId".toLowerCase(), "act.user_id");
		SORT_FIELD.put("securities".toLowerCase(), "sec.securities_pk");
	}


	/** 
	 * 查詢條件-操作日期起
	 */
	@Validate( required=true, on={"doQuery"}, converter=DateTypeConverter.class)
	private Date qryOperationDateFrom;

	/**
	 * 查詢條件-操作時間起
	 */
	private Integer qryOperationDateHourFrom;

	/**
	 * 查詢條件-操作日期迄
	 */
	@Validate( required=true, on={"doQuery"}, converter=DateTypeConverter.class)
	private Date qryOperationDateTo;

	/**
	 * 查詢條件-操作時間迄
	 */
	private Integer qryOperationDateHourTo;

	/**
	 * 查詢條件-使用者ID
	 */
	private String qryUserId;

	/**
	 * 查詢條件-分公司
	 */
	private List<String> qryBranch; 

	/**
	 * 鈎選的子程式清單
	 */
	private String qryActionBeans;    

	/**
	 * 是否為全部選
	 */
	private boolean isSelectNone;

	/**	
	 * 功能選單
	 */
	@SpringBean("menuLoader")
	private MenuLoader menuLoader;

	/**
	 * 分公司表 
	 */
	private Map<String, LabelValue> actionLogSecuritiesMap;

	/**
	 * 全選分公司
	 */
	private String qrySelectAllbranch;

	/**
	 * 公司群組
	 */
	private String qrySelectGroup;

	/**
	 * 查詢結果(多筆)
	 */
	private PaginatedList<ActionLog> queryResult;

	@SpringBean("actionLogService")
	private ActionLogService actionLogService;

	@SpringBean("securitiesService")
	private SecuritiesService securitiesService;

	@SpringBean("groupService")
	private GroupService groupService;

	@SpringBean("messageSource")
	protected ResourceBundleMessageSource messageSource;

	private String message;

	private Group queryGroup;

	@DontBind
	@DefaultHandler
	public Resolution doDefault()
	{
		logger.debug("Enter doDefault method.");
		qryOperationDateFrom = new Date();
		qryOperationDateTo = new Date();
		qryOperationDateHourFrom = new Integer(0);
		qryOperationDateHourTo = new Integer(24);
		return new ForwardResolution(DEFAULT_JSP); 
	}

	/**
	 * 根據用戶選擇的群組返回相應的分公司
	 * @return
	 */
	public Resolution doSelectGroup(){
		logger.debug("Enter doSelectGroup method");
		//刷新分公司
		this.actionLogSecuritiesMap = new LinkedHashMap<String, LabelValue>();
		if(StringUtils.isNotEmpty(this.qrySelectGroup)){

			/* 用groupPk抓取groupType,用來判斷分公司是否要顯示 */
			this.queryGroup = groupService.getByGroupPk(Long.parseLong(this.qrySelectGroup));


			/* 分公司查詢結果 */
			List<Securities> tempBranch = new ArrayList<Securities>();
			/* 用戶選擇的GroupPk */
			List<String> tempGroupList = new ArrayList<String>();
			tempGroupList.add(this.qrySelectGroup);

			/* 調用查詢方法 */
			try {
				tempBranch = securitiesService.findForSecuritiesListByGroupPks(tempGroupList);
			} catch (Exception e) {
				tempBranch = null;
				logger.debug("Error found in the doSelectGroup method where try to get tempBranch!");
			}
			if(CollectionUtils.isNotEmpty(tempBranch)){
				//分公司查詢結果長度
				int j = tempBranch.size();
				for(int i = 0; i < j; i++){
					LabelValue labelValue = new LabelValue();
					labelValue.setLabel(tempBranch.get(i).getSecuritiesName());
					labelValue.setValue(tempBranch.get(i).getSecuritiesPk().toString());
					this.actionLogSecuritiesMap.put(tempBranch.get(i).getSecuritiesName(), labelValue);
				}
			}
			if(StringUtils.isEmpty(this.qryActionBeans)){
				//激活全不選
				this.isSelectNone = true;
			}
		}
		return new ForwardResolution(DEFAULT_JSP);
	}

	/**
	 * 查詢
	 * @return
	 */
	public Resolution doQuery()
	{
		logger.debug("Enter doQuery mehtod.");
		//logger.debug("qryOperationDateFrom={}, qryOperationDateHourFrom={}, qryOperationDateTo={}, qryOperationDateHourTo={}, qryUserId={}, qryTypeOfOperations={} ", new Object[]{qryOperationDateFrom, qryOperationDateHourFrom, qryOperationDateTo, qryOperationDateHourTo, qryUserId, qryBranch});

		/* 設定換頁、排序等條件*/
		PaginatedList<ActionLog> qryCondition = new PaginatedList<ActionLog >();
		String sortCriterion = "in_date_time";
		int sortDirection = 1;
		if(null != queryResult) {
			sortCriterion = queryResult.getSortCriterion();
			sortDirection = queryResult.getSortDirection();
			logger.debug(" sortCriterion={}  sortDirection={} ", new Object[]{queryResult.getSortCriterion(), queryResult.getSortDirection()});
			qryCondition.setPageNumber(queryResult.getPageNumber());
			qryCondition.setPageSize(queryResult.getPageSize());
			String StringSortCriterion=SORT_FIELD.get(sortCriterion.toLowerCase());
			qryCondition.setSortCriterion(StringSortCriterion);
			qryCondition.setSortDirection(sortDirection);
			logger.debug(" qryCondition:sortCriterion={}  sortDirection={} ", new Object[]{qryCondition.getSortCriterion(), qryCondition.getSortDirection()});
		}

		/*沒有設定排序就以第一欄作排序條件*/
		if (null == queryResult || StringUtils.isEmpty(queryResult.getSortCriterion()) || !SORT_KEYS.contains(queryResult.getSortCriterion().toLowerCase()))
		{
			qryCondition.setSortCriterion(SORT_FIELD.get(SORT_KEYS.get(0)));
		}

		/* 設置臨時變量儲存篩選條件 */
		ActionLog tempActionLog = new ActionLog();
		/* 設定查詢條件-操作日期*/
		if(null != this.qryOperationDateFrom && null != this.qryOperationDateTo){
			Calendar cal = Calendar.getInstance();
			/* 設定查詢條件-操作日期起*/
			cal.setTime(this.qryOperationDateFrom);
			cal.set(Calendar.HOUR_OF_DAY, this.qryOperationDateHourFrom);
			this.qryOperationDateFrom = cal.getTime();        
			tempActionLog.setInDateTime(this.qryOperationDateFrom);

			/* 設定查詢條件-操作日期迄*/
			cal.setTime(this.qryOperationDateTo);
			cal.set(Calendar.HOUR_OF_DAY, this.qryOperationDateHourTo);
			this.qryOperationDateTo = cal.getTime();
			tempActionLog.setOutDateTime(this.qryOperationDateTo);
		}
		/* 設定查詢條件-使用者ID */
		if (StringUtils.isNotEmpty(this.qryUserId))
		{
			tempActionLog.setUserId(qryUserId);
		}
		/* 設定查詢條件-功能名稱 */
		String tempSecurities = "";
		if(StringUtils.isNotEmpty(this.qryActionBeans)){        	            
			if (null != this.qryActionBeans)
			{
				String[] abs = this.qryActionBeans.split(",");
				for(int i = 0 ; i < abs.length ; i++ ) {
					if (null != abs[i])
					{
						if( i == 0){
							tempSecurities += abs[i];
						}else{
							tempSecurities += ", " + abs[i];
						}
					}
				}
			}
			tempActionLog.setActionName(tempSecurities);        	
		}
		//如果用戶什麽都沒有選擇，那麼則激活用戶‘全不選’的變量
		else{
			this.isSelectNone = true;
		}

		/* 設定查詢條件-分公司 */
		String tempSecuritiesAsList = "";
		if (CollectionUtils.isNotEmpty(this.qryBranch)) {
			boolean IsFirstTime = true;
			for(String qrySecurities : this.qryBranch) {
				if (StringUtils.isNotEmpty(qrySecurities)){
					if(IsFirstTime){
						tempSecuritiesAsList = qrySecurities;
						IsFirstTime = false;
					}else{
						tempSecuritiesAsList += ", " + qrySecurities;
					}
				}
			}
		}

		/* 查詢 */
		this.queryResult = actionLogService.findForPaginatedListByActionLog(tempActionLog, qryCondition, tempSecuritiesAsList);

		logger.debug("queryResult.getFullListSize() {}" ,queryResult.toString());
		logger.debug("queryResult.getTotalPageCount() {}" ,queryResult.getTotalPageCount());
		
	/*	 重新計算頁面頁數 
		if(null != this.queryResult && !"0".equals(queryResult.getPageSize())){
			int tempSize = (queryResult.getFullListSize() % queryResult.getPageSize()) == 0 
			? (queryResult.getFullListSize() / queryResult.getPageSize())
					:((queryResult.getFullListSize() / queryResult.getPageSize())+1);        
			queryResult.setFullListSize(tempSize);
		}*/

		if (null == this.queryResult)
			this.queryResult = qryCondition;

		queryResult.setSortCriterion(sortCriterion);
		queryResult.setSortDirection(sortDirection);

		if (CollectionUtils.isEmpty(this.queryResult.getPaginatedList()))
			this.message = "查無資料！";

		return new ForwardResolution(DEFAULT_JSP); 
	}

	/**
	 * 匯出Excel檔案
	 * @return
	 */
	public Resolution doExportExcel()
	{
		logger.debug("Enter doExportExcelFile mehtod.");







		try {


			/* 銀行端一定要輸入群組代號 */
			if (UserUtil.isBankGroup())
			{
				if (null != qrySelectGroup )
				{
					Group dbGroup = groupService.getByGroupPk(Long.parseLong(this.qrySelectGroup));

					if (null == dbGroup)
					{
						this.message = "券商代號有誤！";
						return new ForwardResolution(DEFAULT_JSP);
					}
					this.queryGroup=dbGroup;
				}
				else
				{
					this.message = "請輸入券商代號！";
					return new ForwardResolution(DEFAULT_JSP);
				}
			}



			/* 設置臨時變量儲存篩選條件 */
			ActionLog tempActionLog = new ActionLog();
			/* 設定查詢條件-操作日期*/
			if(null != this.qryOperationDateFrom && null != this.qryOperationDateTo){
				Calendar cal = Calendar.getInstance();
				/* 設定查詢條件-操作日期起*/
				cal.setTime(this.qryOperationDateFrom);
				cal.set(Calendar.HOUR_OF_DAY, this.qryOperationDateHourFrom);
				this.qryOperationDateFrom = cal.getTime();        
				tempActionLog.setInDateTime(this.qryOperationDateFrom);

				/* 設定查詢條件-操作日期迄*/
				cal.setTime(this.qryOperationDateTo);
				cal.set(Calendar.HOUR_OF_DAY, this.qryOperationDateHourTo);
				this.qryOperationDateTo = cal.getTime();
				tempActionLog.setOutDateTime(this.qryOperationDateTo);
			}else{

				this.message = "請輸入操作日期！";
				return new ForwardResolution(DEFAULT_JSP);
			}



			/* 設定查詢條件-使用者ID */
			if (StringUtils.isNotEmpty(this.qryUserId))
			{
				tempActionLog.setUserId(qryUserId);
			}
			/* 設定查詢條件-功能名稱 */
			String tempSecurities = "";
			if(StringUtils.isNotEmpty(this.qryActionBeans)){        	            
				if (null != this.qryActionBeans)
				{
					String[] abs = this.qryActionBeans.split(",");
					for(int i = 0 ; i < abs.length ; i++ ) {
						if (null != abs[i])
						{
							if( i == 0){
								tempSecurities += abs[i];
							}else{
								tempSecurities += ", " + abs[i];
							}
						}
					}
				}
				tempActionLog.setActionName(tempSecurities);        	
			}
			//如果用戶什麽都沒有選擇，那麼則激活用戶‘全不選’的變量
			else{
				this.isSelectNone = true;
			}

			/* 設定查詢條件-分公司 */
			String tempSecuritiesAsList = "";
			if (CollectionUtils.isNotEmpty(this.qryBranch)) {
				boolean IsFirstTime = true;
				for(String qrySecurities : this.qryBranch) {
					if (StringUtils.isNotEmpty(qrySecurities)){
						if(IsFirstTime){
							tempSecuritiesAsList = qrySecurities;
							IsFirstTime = false;
						}else{
							tempSecuritiesAsList += ", " + qrySecurities;
						}
					}
				}
			}

			/* 查詢 */
			//	this.queryResult = actionLogService.findForPaginatedListByActionLog(tempActionLog, qryCondition, tempSecuritiesAsList);


			String downloadFilePath = "";


			/* 設定換頁、排序等條件*/
			PaginatedList<ActionLog> qryCondition = new PaginatedList<ActionLog >();
			String sortCriterion = "in_date_time";
			int sortDirection = 1;
			if(null != queryResult) {
				sortCriterion = queryResult.getSortCriterion();
				sortDirection = queryResult.getSortDirection();
				logger.debug(" sortCriterion={}  sortDirection={} ", new Object[]{queryResult.getSortCriterion(), queryResult.getSortDirection()});
				//qryCondition.setPageNumber(queryResult.getPageNumber());
				//qryCondition.setPageSize(queryResult.getPageSize());
				String StringSortCriterion=SORT_FIELD.get(sortCriterion.toLowerCase());
				qryCondition.setSortCriterion(StringSortCriterion);
				qryCondition.setSortDirection(sortDirection);
				logger.debug(" qryCondition:sortCriterion={}  sortDirection={} ", new Object[]{qryCondition.getSortCriterion(), qryCondition.getSortDirection()});
			}

			/*沒有設定排序就以第一欄作排序條件*/
			if (null == queryResult || StringUtils.isEmpty(queryResult.getSortCriterion()) || !SORT_KEYS.contains(queryResult.getSortCriterion().toLowerCase()))
			{
				qryCondition.setSortCriterion(SORT_FIELD.get(SORT_KEYS.get(0)));
			}


			downloadFilePath = actionLogService.exportExcelByPaymentFileContent(tempActionLog, qryCondition, tempSecuritiesAsList);
			if (StringUtils.isEmpty(downloadFilePath))
			{
				this.message = messageSource.getMessage("query.nothing", null, "查無資料！", this.getContext().getRequest().getLocale());
				return doQuery();
			}


			File downloadFile = new File(downloadFilePath);
			byte[] bytes = new byte[(int)downloadFile.length()];

			BufferedInputStream bufferedInputStream = 
				new BufferedInputStream(new FileInputStream(downloadFile)); 

			bufferedInputStream.read(bytes);

			ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
			inputStream.close();
			bufferedInputStream.close();

			String isoFileName = new String("操作記錄查詢.xls".getBytes("MS950"), "ISO8859-1");

			StreamingResolution streamingResolution = new StreamingResolution("application/vnd.ms-excel",inputStream).setFilename(isoFileName);

			return streamingResolution;
		} catch (Exception e) {
			logger.error("", e);
		}
		return doQuery(); 
	}

	/**
	 * 獲取分公司
	 */
	public Collection<LabelValue> getBranch()
	{
		//臨時變量來判斷是否存在數據
		boolean isActionLogSecuritiesMapNull = false;
		if(null == this.actionLogSecuritiesMap){
			isActionLogSecuritiesMapNull = true;
		}else{
			if(this.actionLogSecuritiesMap.size() == 0) isActionLogSecuritiesMapNull = true;
		}

		if (isActionLogSecuritiesMapNull)
		{
			/* 是否為銀行群組 */
			boolean isBankGroup = UserUtil.isBankGroup();
			/* 分公司查詢結果 */
			List<Securities> tempBranch = new ArrayList<Securities>();
			/* 如果不是銀行群組，則獲取登陸者當前帳號可處理券商的資料 */
			if(!isBankGroup){
				//獲取當前登錄用戶
				User user = UserUtil.getUser();
				//取得當前登錄用戶的可處理券商資料
				String userDealSecuritiesNos = user.getDealSecuritiesNos();
				List<String> tempDealSecuritiesNo = new ArrayList<String>();
				if(StringUtils.isNotEmpty(userDealSecuritiesNos)){
					String[] abs = userDealSecuritiesNos.split(",");
					for(String securitiesNo:abs){
						if(null != securitiesNo){
							tempDealSecuritiesNo.add(securitiesNo);
						}
					}
				}
				/* 調用查詢方法 */
				try {
					tempBranch = securitiesService.findForSecuritiesListBySecuritiesNos(tempDealSecuritiesNo);
				} catch (Exception e) {
					tempBranch = null;
					logger.debug("Error in getBranch() method when login user is normal user for find for securities list by group Pk!");
				}

			}
			/* 如果是銀行群組，則可以查詢所有分公司的資料 */
			else{
				//取得當前選擇處理券商的資料
				List<String> tempUserGroupPk = new ArrayList<String>();
				if(StringUtils.isNotEmpty(this.qrySelectGroup)){
					tempUserGroupPk.add(this.qrySelectGroup);
				}else{
					//獲取當前登錄用戶
					User user = UserUtil.getUser();
					//取得當前登錄用戶的可處理券商資料
					String userGroupPk = user.getGroup().getGroupPk().toString();
					tempUserGroupPk.add(userGroupPk);
				}
				/* 調用查詢 */
				try {
					tempBranch = securitiesService.findForSecuritiesListByGroupPks(tempUserGroupPk);
				} catch (Exception e) {
					tempBranch = null;
					logger.debug("Error in getBranch() method when login user is bank group for find for securities list by group Pk!");
				}

			}



			this.actionLogSecuritiesMap = new LinkedHashMap<String, LabelValue>();
			if(null != tempBranch && tempBranch.size()>0){
				//分公司查詢結果長度
				int j = tempBranch.size();
				for(int i = 0; i < j; i++){
					LabelValue labelValue = new LabelValue();
					labelValue.setLabel(tempBranch.get(i).getSecuritiesName());
					labelValue.setValue(tempBranch.get(i).getSecuritiesPk().toString());
					this.actionLogSecuritiesMap.put(tempBranch.get(i).getSecuritiesName(), labelValue);
				}
			}
		}		
		return this.actionLogSecuritiesMap.values();
	}

	/**
	 * 返回功能名稱表
	 * @return
	 */
	public List<List> getFunctionsList() {
		/* 總List */
		List<List> sumList = new ArrayList<List>();
		/* 某一程式群組及其下程式功能 */
		List<LabelValue> tmpList = new ArrayList<LabelValue>();

		/* 動態獲取程式中菜單 */
		List<MenuItem> menuItem = new ArrayList<MenuItem>();
		menuItem = menuLoader.getMenuItems();
		/* 如果菜單不為空則導入菜單到List中 */
		if(menuItem != null && menuItem.size() > 0){
			int menuItemSize = menuItem.size();

			/* 獲取用戶選擇的查詢條件-功能名稱 */
			List<String> tempActionBeans = new ArrayList<String>();
			if(StringUtils.isNotEmpty(this.qryActionBeans)){        	            
				if (null != this.qryActionBeans)
				{
					String[] abs = this.qryActionBeans.split(",");
					for(String actionBean: abs)
					{
						if (null != actionBean)
						{
							tempActionBeans.add(actionBean);
						}
					}
				}            
			}
			/* 循環添加功能名稱 */
			for (int i = 0; i < menuItemSize; i++) {
				/* 只有當數據庫中父菜單ID及ActionBeanClass為空才為父菜單 */
				boolean isParentMenu = (menuItem.get(i).getParentMenuItem() == null || "".equals(menuItem.get(i).getParentMenuItem()))
				&& (menuItem.get(i).getActionBeanClass() == null || "".equals(menuItem.get(i).getActionBeanClass()));
				/* 如果是父菜單，則創建新的List來保存其及其下相關程式功能 */
				if(isParentMenu){
					/* 每次遇到不為空的父菜單，都把上一個List提交，并創建新的List */
					if(tmpList != null && tmpList.size() > 1){
						sumList.add(tmpList);
					}
					/* 當用戶已經選擇過功能名稱時，保存已經選擇的選項 */
					if(null != tempActionBeans && tempActionBeans.size() > 0){
						int actionBeansSize = tempActionBeans.size();
						tmpList = new ArrayList<LabelValue>();
						LabelValue labelValue = new LabelValue();
						labelValue.setLabel(menuItem.get(i).getActionName());
						labelValue.setValue(menuItem.get(i).getMenuItemPk().toString());
						boolean isEqual = false;
						for (int k = 0; k < actionBeansSize; k++) {
							String selectedItem = tempActionBeans.get(k);
							isEqual = selectedItem.equals(menuItem.get(i).getMenuItemPk().toString());
							//當遇到匹配的情況，則保存選項，并跳出循環.
							if(isEqual){
								labelValue.setChecked(true);
								break;
							}
						}
						if(!isEqual){
							labelValue.setChecked(false);
						}
						tmpList.add(labelValue);
					}else{
						tmpList = new ArrayList<LabelValue>();
						LabelValue labelValue = new LabelValue();
						labelValue.setLabel(menuItem.get(i).getActionName());
						labelValue.setValue(menuItem.get(i).getMenuItemPk().toString());
						if(isSelectNone){
							labelValue.setChecked(false);
						}else{
							labelValue.setChecked(true);
						}											
						tmpList.add(labelValue);
					}
				}
				/* 子菜單的保存 */
				else {
					/*當用戶已經選擇過功能名稱時，保存已經選擇的選項 */
					if(null != tempActionBeans && tempActionBeans.size() > 0){
						int actionBeansSize = tempActionBeans.size();						
						LabelValue labelValue = new LabelValue();
						labelValue.setLabel(menuItem.get(i).getActionName());
						labelValue.setValue(menuItem.get(i).getMenuItemPk().toString());
						boolean isEqual = false;
						for (int k = 0; k < actionBeansSize; k++) {
							String selectedItem = tempActionBeans.get(k);
							isEqual = selectedItem.equals(menuItem.get(i).getMenuItemPk().toString());
//							當遇到匹配的情況，則保存選項，并跳出循環.
							if(isEqual){
								labelValue.setChecked(true);
								break;
							}
						}
						if(!isEqual){
							labelValue.setChecked(false);
						}
						tmpList.add(labelValue);
					}else{
						LabelValue labelValue = new LabelValue();
						labelValue.setLabel(menuItem.get(i).getActionName());
						labelValue.setValue(menuItem.get(i).getMenuItemPk().toString());
						if(isSelectNone){
							labelValue.setChecked(false);
						}else{
							labelValue.setChecked(true);
						}								
						tmpList.add(labelValue);
					}				
					/* 提交最後一筆，當且僅當該程式為子菜單時 */
					if(i == menuItemSize - 1){
						sumList.add(tmpList);
					}
				}				
			}
		}    	
		return sumList;
	}

	/**
	 * @return selectedGroup
	 */
	public List<LabelValue> getSelectedGroup() {
		/* 查詢該角色權限下的用戶 */
		//如果資料清空
		List<LabelValue> selectedGroup = new ArrayList<LabelValue>();
		//是銀行群組--列出該角色下的所有用戶
		//保存查詢到得用戶
		List<Group> tempGroup;
		//去數據庫查詢資料
		try {
			tempGroup = groupService.findAllGroup();
		} catch (Exception e) {
			tempGroup = null;
		}
		//轉化資料為可用數據
		if(null != tempGroup && tempGroup.size() > 0){
			LabelValue labelValue;
			for(int i = 0 ; i < tempGroup.size() ; i++){
				labelValue = new LabelValue();
				//顯示為 群組No + 用戶ID  要不然頁面名稱容易混亂，不易區分
				labelValue.setLabel(tempGroup.get(i).getGroupName());
				labelValue.setValue(tempGroup.get(i).getGroupPk().toString());
				selectedGroup.add(labelValue);
			}
		}
		return selectedGroup;
	}

	/**
	 * @return message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message 的設定的 message
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	// queryGroup
	/**
	 * @return queryGroup
	 * 用groupPk至app_group抓取資料
	 */
	public Group getQueryGroup() {
		return queryGroup;
	}

	/**
	 * @param queryGroup 的設定的 queryGroup
	 */
	public void setQueryGroup(Group group) {
		this.queryGroup = group;
	}


	/**
	 * @return qryOperationDateFrom
	 */
	public Date getQryOperationDateFrom() {
		return qryOperationDateFrom;
	}

	/**
	 * @param qryOperationDateFrom 的設定的 qryOperationDateFrom
	 */
	public void setQryOperationDateFrom(Date qryOperationDateFrom) {
		this.qryOperationDateFrom = qryOperationDateFrom;
	}

	/**
	 * @return qryOperationDateHourFrom
	 */
	public Integer getQryOperationDateHourFrom() {
		return qryOperationDateHourFrom;
	}

	/**
	 * @param qryOperationDateHourFrom 的設定的 qryOperationDateHourFrom
	 */
	public void setQryOperationDateHourFrom(Integer qryOperationDateHourFrom) {
		this.qryOperationDateHourFrom = qryOperationDateHourFrom;
	}

	/**
	 * @return qryOperationDateHourTo
	 */
	public Integer getQryOperationDateHourTo() {
		return qryOperationDateHourTo;
	}

	/**
	 * @param qryOperationDateHourTo 的設定的 qryOperationDateHourTo
	 */
	public void setQryOperationDateHourTo(Integer qryOperationDateHourTo) {
		this.qryOperationDateHourTo = qryOperationDateHourTo;
	}

	/**
	 * @return qryOperationDateTo
	 */
	public Date getQryOperationDateTo() {
		return qryOperationDateTo;
	}

	/**
	 * @param qryOperationDateTo 的設定的 qryOperationDateTo
	 */
	public void setQryOperationDateTo(Date qryOperationDateTo) {
		this.qryOperationDateTo = qryOperationDateTo;
	}

	/**
	 * @return qryBranch
	 */
	public List<String> getQryBranch() {
		return qryBranch;
	}

	/**
	 * @param qryBranch 的設定的 qryBranch
	 */
	public void setQryBranch(List<String> qryBranch) {
		this.qryBranch = qryBranch;
	}

	/**
	 * @return qryUserId
	 */
	public String getQryUserId() {
		return qryUserId;
	}

	/**
	 * @param qryUserId 的設定的 qryUserId
	 */
	public void setQryUserId(String qryUserId) {
		this.qryUserId = qryUserId;
	}


	/**
	 * @return qrySelectAllbranch
	 */
	public String getQrySelectAllbranch() {
		return qrySelectAllbranch;
	}

	/**
	 * @param qrySelectAllbranch 的設定的 qrySelectAllbranch
	 */
	public void setQrySelectAllbranch(String qrySelectAllbranch) {
		this.qrySelectAllbranch = qrySelectAllbranch;
	}

	public PaginatedList<ActionLog> getQueryResult() {
		return queryResult;
	}

	public void setQueryResult(PaginatedList<ActionLog> queryResult) {
		this.queryResult = queryResult;
	}

	public String getQryActionBeans() {
		return qryActionBeans;
	}

	public void setQryActionBeans(String qryActionBeans) {
		this.qryActionBeans = qryActionBeans;
	}

	/**
	 * @return isSelectNone
	 */
	public boolean isSelectNone() {
		return isSelectNone;
	}

	/**
	 * @param isSelectNone 的設定的 isSelectNone
	 */
	public void setSelectNone(boolean isSelectNone) {
		this.isSelectNone = isSelectNone;
	}

	/**
	 * @return qrySelectGroup
	 */
	public String getQrySelectGroup() {
		return qrySelectGroup;
	}

	/**
	 * @param qrySelectGroup 的設定的 qrySelectGroup
	 */
	public void setQrySelectGroup(String qrySelectGroup) {
		this.qrySelectGroup = qrySelectGroup;
	}

	/**
	 * @return isBankGroupUser
	 */
	public Boolean getIsBankGroupUser() {
		boolean tempIsBankGroupUser = UserUtil.isBankGroup();
		return tempIsBankGroupUser;
	}
}
